package com.xm.limiter;

public class LimiterTest {
    public static void main(String[] args) {
        newThread(new CounterLimiter01(5, 1000));
        newThread(new SlidingWindowLimiter02(5, 1000, 10));
        newThread(new TokenBucketLimiter03(5, 1000));
        newThread(new LeakyBucketLimiter04(5, 1000));
    }

    /**
     * 多线程测试
     */
    public static void newThread(Limiter limiter) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("---------------------------------------");
        TryAcquireStrategy strategy = new TryAcquireStrategy(limiter);
        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                boolean result = strategy.tryAcquire();
                System.out.println(result);
            }
        }).start();
    }
}
